export default {
  // 全局页面头部配置
  head: {
    title: '登录系统',
    htmlAttrs: {
      lang: 'zh'
    },
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: '用户登录和个人主页系统' }
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
    ]
  },

  // 全局CSS
  css: [
    '~/assets/css/main.css'
  ],

  // 插件配置
  plugins: [
    '~/plugins/axios.js'
  ],

  // 自动导入组件
  components: true,

  // 构建配置模块
  buildModules: [
    '@nuxtjs/vuetify',
  ],

  // Vuetify配置
  vuetify: {
    customVariables: ['~/assets/scss/variables.scss'],
    treeShake: true,
    optionsPath: '~/plugins/vuetify.options.js'
  },

  // 模块配置
  modules: [
    '@nuxtjs/axios',
    '@nuxtjs/auth-next',
    '@nuxtjs/i18n',
  ],

  // Axios 模块配置
  axios: {
    baseURL: process.env.API_URL || 'http://localhost:3000/api',
    credentials: true
  },

  // Auth 模块配置
  auth: {
    strategies: {
      local: {
        token: {
          property: 'token',
          required: true,
          type: 'Bearer'
        },
        user: {
          property: 'user'
        },
        endpoints: {
          login: { url: '/auth/login', method: 'post' },
          logout: { url: '/auth/logout', method: 'post' },
          user: { url: '/auth/user', method: 'get' }
        }
      },
      google: {
        clientId: process.env.GOOGLE_CLIENT_ID,
        codeChallengeMethod: '',
        responseType: 'code',
        endpoints: {
          token: '/api/auth/google',
          userInfo: '/api/auth/user'
        },
        scope: ['profile', 'email']
      }
    },
    redirect: {
      login: '/login',
      logout: '/',
      callback: '/login',
      home: '/dashboard'
    }
  },

  // i18n 国际化配置
  i18n: {
    locales: [
      { code: 'en', name: 'English', file: 'en.js' },
      { code: 'zh', name: '中文', file: 'zh.js' }
    ],
    defaultLocale: 'zh',
    langDir: '~/locales/',
    strategy: 'no_prefix',
    vuex: true,
    vueI18n: {
      fallbackLocale: 'en'
    },
    detectBrowserLanguage: {
      useCookie: true,
      cookieKey: 'i18n_redirected',
      redirectOn: 'root'
    }
  },

  // Vuetify 配置
  vuetify: {
    customVariables: ['~/assets/scss/variables.scss'],
    treeShake: true,
    theme: {
      dark: false,
      themes: {
        light: {
          primary: '#1976D2',
          secondary: '#424242',
          accent: '#82B1FF',
          error: '#FF5252',
          info: '#2196F3',
          success: '#4CAF50',
          warning: '#FFC107'
        }
      }
    }
  },

  // 服务器中间件
  serverMiddleware: [
    { path: '/api', handler: '~/server/index.js' }
  ],

  // 构建配置
  build: {
    // 添加构建优化配置
    transpile: [/^vuetify/],
    extend(config, { isDev, isClient }) {
      // 开发环境配置
      if (isDev && isClient) {
        config.devtool = 'source-map'
      }
    }
  }
}